<?php
require_once("include.php");
require_once("workobj.php");
session_start();
include("showmenu.php");
//authorise("userinput");
(isset($_REQUEST["restart"])) ? $restart = $_REQUEST["restart"] : $restart = "NULL" ;
(isset($_REQUEST["res"])) ? $res = $_REQUEST["res"] : $res = "NULL" ;
(isset($_REQUEST["sub"])) ? $sub = $_REQUEST["sub"] : $sub = "NULL" ;
(isset($_REQUEST["itemid"])) ? $itemid = $_REQUEST["itemid"] : $itemid = "NULL" ;
(isset($_REQUEST["copyfrom"])) ? $copyfrom = $_REQUEST["copyfrom"] : $copyfrom = "NULL" ;
(isset($_REQUEST["copyto"])) ? $copyto = $_REQUEST["copyto"] : $copyto = "NULL" ;
(isset($_REQUEST["empid"])) ? $empid = $_REQUEST["empid"] : $empid = "NULL" ;
(isset($_REQUEST["showfrom"])) ? $showfrom = @$_REQUEST["showfrom"] : $showfrom = "NULL";
(isset($_REQUEST["showto"])) ? $showto = @$_REQUEST["showto"] : $showto = "NULL";
 

if (!(isset($_SESSION["attendance"]))) {$obj = new attendance();}
$obj=&$_SESSION["attendance"] ;
if ($obj->header[2] !== "") {
 // have already read or created an item
 $obj->applyfromrequest();
 if ($sub == "Save" && $obj->valid) {
  if ($obj->writedb()) {
   $obj->confirmfiled("",$showfrom,$showto);
   unset($_SESSION["attendance"]);
  } else {
 
   $obj->showfail();
  }
 } elseif($res=="restart") {
  unset($_SESSION["attendance"]);
 } else {
  $obj->showform();
 }
} elseif ($sub=="Copy") {
 if ($copyfrom != "-1" && $copyfrom != "NULL" && $copyto != "-1" && $copyto != "NULL") {
  $obj->copyday($copyfrom,$copyto);
 }
 $obj->showall($showfrom,$showto);
} elseif($empid != "NULL" && $empid !="-1") {
 $obj->createblank();
 $obj->header[5] = $empid;
 $obj->showform();
} elseif ($itemid != "NULL") {
 if ($obj->readdb($itemid)) {
  $obj->showform();
 } else {
  $obj->showall($showfrom,$showto);
 } 
} else {
 $obj->showall($showfrom,$showto);
}
?>